/* Copyright 2008. All rights reserved. */
package org.bling.parser.tags;

import org.bling.parser.BlingParserException;
import org.bling.swt.BlingLayout;
import org.bling.swt.BlingLayoutData;
import org.bling.util.Constants;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Widget;

/**
 * renders an SWT Group
 * 
 * @author DISBROB
 * 
 */
public class GroupTag extends Tag {

	protected Group group;
	protected String title;

	public void setTitle(String title) {
		this.title = title;
	}

	@Override
	public int doStartTag() throws BlingParserException {
		super.doStartTag();

		if (!(parent.getWidget() instanceof Composite)) {
			throw new BlingParserException(
					"Label tags can only be inside of composites");
		}

		Composite composite = (Composite) parent.getWidget();
		group = new Group(composite, SWT.SHADOW_ETCHED_OUT);
		group.setText(title);
		group.setLayout(new BlingLayout());
		BlingLayoutData data = new BlingLayoutData();
		data.marginTop = Constants.Margins.DEFAULT_COMPOSITE_TOP;
		data.marginBottom = Constants.Margins.DEFAULT_COMPOSITE_BOTTOM;
		data.marginLeft = Constants.Margins.DEFAULT_COMPOSITE_LEFT;
		data.marginRight = Constants.Margins.DEFAULT_COMPOSITE_RIGHT;
		group.setLayoutData(data);

		return EVAL_PAGE;
	}

	@Override
	public Widget getWidget() throws BlingParserException {
		return group;
	}

}
